 <?php 
	//echo $_GET['id1'];
	require_once 'includefiles.php';	
	require_once 'model/users.php';
	require_once 'model/state.php';
	
	
	$userObj = new Model_Users();
	$stateObj = new Model_State();
	
	
	$userId =$_SESSION['getbids_id'];
	if($userId!='')
	{
		$userDetArray = $userObj->getUserDetailsByUserId($userId);	
	}
	
    require('google_map/GoogleMapAPIforinner.class.php');
    $map = new GoogleMapAPI('map'); 
	
	//$map->setAPIKey('AIzaSyBEDztDHGYOtblfCUpRFcDhXnrzfHaErMI'); //Local
    $map->setAPIKey('AIzaSyBXASocX9adb1nSZAAGcjmPTQcQ31JHqcM'); //demo
	//$map->setAPIKey('ABQIAAAAGcCuz_gp6NTRiTFcpuMcOxQqPLLIlRB5MAQg1O56GW9RTTZEwxS4n9zr_9-Gcr_QE6SM6ZwNmCxhEQ');// live
	
	// Live By Hiraman
  
 // $map->setAPIKey('ABQIAAAAYoZm3GWERhAO-gZspifC-hRYBlMPB73kdBCen5oBZcKvgOkK5BRh_zYyZbARnm1-J0H5GVxNmN4Cag');// live

    $map->setHeight('180'); 
    $map->setWidth('296');
    ## Getting all jobs from database according to user
	if($_POST['trade']!='0' && $_POST['trade']!='')
	{
		$trade = $_POST['trade'];
	} 
	elseif($_GET['id2']!='' && $_GET['id2']!='trade')
	{
		$trade =base64_decode($_GET['id2']); 
	}
	else 
	{
		$trade = '';
	}
		
	if($_POST['stateid']!='0' && $_POST['stateid']!='')
	{
		$stateid = $_POST['stateid']; 
		if($stateid!='')
		{
			$getstatedetail = $stateObj->getStateDetailsById($stateid);
			$stateid = $getstatedetail['state_id']; 
			$userstatename = $getstatedetail['state_name']; 
			
			$getallpostalcode = $stateObj->getAllSuburb($getstatedetail['iso1_code']);
					
			for($i=0;$i<count($getallpostalcode);$i++)
			{
				$getallpostalcode_arr[] ="'".$getallpostalcode[$i]["postcode"]."'";
			}
			if($getallpostalcode_arr[0]!='')
				$implodearray = @implode(",",$getallpostalcode_arr);
			else
				$implodearray = 0;	
				
			$postalcode = $implodearray;
			
		}
	} 
	elseif($_GET['id3']!='' && $_GET['id3']!='state')
	{
		$stateid =base64_decode($_GET['id3']); 
		if($stateid!='')
		{
			$getstatedetail = $stateObj->getStateDetailsById($stateid);
			$stateid = $getstatedetail['state_id']; 
			$userstatename = $getstatedetail['state_name']; 
			$getallpostalcode = $stateObj->getAllSuburb($getstatedetail['iso1_code']);
					
			for($i=0;$i<count($getallpostalcode);$i++)
			{
				$getallpostalcode_arr[] ="'".$getallpostalcode[$i]["postcode"]."'";
			}
			if($getallpostalcode_arr[0]!='')
				$implodearray = @implode(",",$getallpostalcode_arr);
			else
				$implodearray = 0;	
				
			$postalcode = $implodearray;
		}
	}
	else
	{
		$stateid = '';
	}

	if(($_GET['id2']=='' && $_GET['id3']=='') && ($_POST['trade']=='' && $_POST['stateid']==''))
	{
		if($trade=='')
		{
			$trade = $userDetArray['tradeid']; 
		}
		if($stateid=='')
		{
			if($userDetArray['postalcode']!='')
			{
				$getpostaldetail = $stateObj->getPostalDetailsById($userDetArray['postalcode']);
				$getstatedetail = $stateObj->getStateDetailsByISOCODE($getpostaldetail['state']);
				$stateid = $getstatedetail['state_id']; 
				$userstatename = $getstatedetail['state_name']; 
				$getallpostalcode = $stateObj->getAllSuburb($getstatedetail['iso1_code']);
					
				for($i=0;$i<count($getallpostalcode);$i++)
				{
					$getallpostalcode_arr[] ="'".$getallpostalcode[$i]["postcode"]."'";
				}
				if($getallpostalcode_arr[0]!='')
					$implodearray = @implode(",",$getallpostalcode_arr);
				else
					$implodearray = 0;	
					
				$postalcode = $implodearray;
			}
		}
	}
	$tradesmanArray  = $userObj->FindTradesmanAccordingToAll($trade,$postalcode,'','',false);
	
	for($i=0;$i<count($tradesmanArray);$i++)
	{
		if($tradesmanArray[$i]['postalcode']!='')
		{
			$getpostaldetail = $stateObj->getPostalCodeDetailsByPostalId($tradesmanArray[$i]['postalcode']);
			$getstatedetail = $stateObj->getStateDetailsByISOCODE($getpostaldetail['state']);
			
			$address_arr =$getstatedetail['state_name']; 
		}

	
	
		$map->addMarkerByCoords($getpostaldetail['lon'],$getpostaldetail['lat'],$address_arr); 

	}
			
	
	$map->setControlSize('small');
    $google_map_header=$map->getHeaderJS();
    $google_map_js=$map->getMapJS(); 
    $google_map_sidebar=$map->getSidebar();
    $google_map=$map->getMap(); 
    $onload = $map->getOnLoad(); 
    $zoomlevel=$map->setZoomLevel(6);

    
?>
<?php echo $google_map_header; ?><?php echo $google_map_js; ?>
<?php echo $google_map; echo $onload; echo $zoomlevel; ?>